package org.dromara.system.api.feign.fallback;

import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.system.api.feign.SystemDataScopeClient;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author: zhou shuai
 * @date: 2024/10/5 22:03
 * @version: v1
 */
@Slf4j
@Component
public class SystemDataScopeFallBack implements FallbackFactory<SystemDataScopeClient> {
    @Override
    public SystemDataScopeClient create(Throwable throwable) {
        log.error("SystemDataScopeFallBack, cause:{}", throwable.getMessage());
        return new SystemDataScopeClient() {

            @Override
            public R<String> getRoleCustom(Long roleId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<String> getDeptAndChild(Long deptId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }
        };
    }
}
